<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js light">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>Terminal Examples - Bracket-Lib Usage Guide</title>
        
        


        <!-- Custom HTML head -->
        


        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        
        <link rel="icon" href="favicon.svg">
        
        
        <link rel="shortcut icon" href="favicon.png">
        
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        
        <link rel="stylesheet" href="css/print.css" media="print">
        

        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        
        <link rel="stylesheet" href="fonts/fonts.css">
        

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        

        
    </head>
    <body>
        <!-- Provide site root to javascript -->
        <script type="text/javascript">
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('light')
            html.classList.add(theme);
            html.classList.add('js');
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded "><a href="what_is_it.html"><strong aria-hidden="true">1.</strong> What is Bracket-lib</a></li><li class="chapter-item expanded "><a href="linking.html"><strong aria-hidden="true">2.</strong> Quick Start</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="hello_terminal.html"><strong aria-hidden="true">2.1.</strong> Hello Terminal</a></li><li class="chapter-item expanded "><a href="individual_parts.html"><strong aria-hidden="true">2.2.</strong> Using Individual Components</a></li></ol></li><li class="chapter-item expanded "><a href="examples.html"><strong aria-hidden="true">3.</strong> Using the Examples</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="ex_color.html"><strong aria-hidden="true">3.1.</strong> Color Examples</a></li><li class="chapter-item expanded "><a href="ex_geometry.html"><strong aria-hidden="true">3.2.</strong> Geometry Examples</a></li><li class="chapter-item expanded "><a href="ex_noise.html"><strong aria-hidden="true">3.3.</strong> Noise Examples</a></li><li class="chapter-item expanded "><a href="ex_path.html"><strong aria-hidden="true">3.4.</strong> Pathfinding Examples</a></li><li class="chapter-item expanded "><a href="ex_rng.html"><strong aria-hidden="true">3.5.</strong> Random Examples</a></li><li class="chapter-item expanded "><a href="ex_bterm.html" class="active"><strong aria-hidden="true">3.6.</strong> Terminal Examples</a></li></ol></li><li class="chapter-item expanded "><a href="consoles.html"><strong aria-hidden="true">4.</strong> Working with Consoles</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="consoles_print.html"><strong aria-hidden="true">4.1.</strong> Printing to Consoles</a></li></ol></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                
                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky bordered">
                    <div class="left-buttons">
                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </button>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                        
                    </div>

                    <h1 class="menu-title">Bracket-Lib Usage Guide</h1>

                    <div class="right-buttons">
                        
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                        
                        
                    </div>
                </div>

                
                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" name="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>
                

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1><a class="header" href="#terminal-examples" id="terminal-examples">Terminal Examples</a></h1>
<h2><a class="header" href="#alpha" id="alpha">alpha</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/alpha.rs">Source Code</a></p>
<p>Demonstrates the RGBA capabilities of the library, when alpha blending is enabled on a sparse console overlaying a simple console. Also uses the <code>VirtualConsole</code> feature to create a large psuedo-console containing a chunk of <em>A Tale of Two Cities</em>, and rendering that as the base layer.</p>
<p><img src="./ex_bt_alpha.gif" alt="" /></p>
<h2><a class="header" href="#astar_mouse" id="astar_mouse">astar_mouse</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/astar_mouse.rs">Source Code</a></p>
<p>Generates a random blob map, and places a player on it. The player moves to wherever the mouse is clicked, using A star pathfinding. Also generates real-time field of view for the player as they zip around.</p>
<p><img src="./ex_bt_astar_mouse.gif" alt="" /></p>
<h2><a class="header" href="#bench_scalable" id="bench_scalable">bench_scalable</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/bench_scalable.rs">Source Code</a></p>
<p>Generates a completely random console, as fast as possible. Uses the resizable console option to allow the window to be resized while it runs, and queries the console for dimensions---filling as much of it as possible.</p>
<p>No screenshot, sorry.</p>
<h2><a class="header" href="#benchmark" id="benchmark">benchmark</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/benchmark.rs">Source Code</a></p>
<p>Draws a random console as fast as possible. No resizing.</p>
<h2><a class="header" href="#colorfont" id="colorfont">colorfont</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/colorfont.rs">Source Code</a></p>
<p>Demonstrates that you can use color in your font graphic if you want to.</p>
<p><img src="./ex_bt_colorfont.jpg" alt="" /></p>
<h2><a class="header" href="#dwarfmap" id="dwarfmap">dwarfmap</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/dwarfmap.rs">Source Code</a></p>
<p>An homage to <em>Dwarf Fortress</em>. Generates a 3D map, and then renders it top-down with darkening for lower than the player z-levels. Implements a-star pathing in 3D, and mouse-based navigation.</p>
<p><img src="./ex_bt_dwarfmap.gif" alt="" /></p>
<h2><a class="header" href="#flexible" id="flexible">flexible</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/flexible.rs">Source Code</a></p>
<p>Demonstrates using a fancy/flexible console to make a spinning <code>@</code> bounce around the screen.</p>
<p><img src="./ex_bt_flex.gif" alt="" /></p>
<h2><a class="header" href="#fontswitch" id="fontswitch">fontswitch</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/fontswitch.rs">Source Code</a></p>
<p>Demonstrates switching fonts at run-time.</p>
<p><img src="./ex_bt_fontswitch.gif" alt="" /></p>
<h2><a class="header" href="#hello_minimal" id="hello_minimal">hello_minimal</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/hello_minimal.rs">Source Code</a></p>
<p>Minimal hello world, see the quick start guide.</p>
<h2><a class="header" href="#hello_terminal" id="hello_terminal">hello_terminal</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/hello_terminal.rs">Source Code</a></p>
<p>See the quick start guide---a bouncing hello world.</p>
<p><img src="./ex_bt_hello_terminal.gif" alt="" /></p>
<h2><a class="header" href="#input_harness" id="input_harness">input_harness</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/input_harness.rs">Source Code</a></p>
<p>A handy tool to display the key code and mouse information about keys/mouse as they are utilized. Also demonstrates the <code>advanced_input</code> system, providing inputs as a stream of events rather than a simple set.</p>
<p><img src="./ex_bt_input_harness.jpg" alt="" /></p>
<h2><a class="header" href="#keyboard" id="keyboard">keyboard</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/keyboard.rs">Source Code</a></p>
<p>Mostly a debugging tool. Demonstrates keys and their various modifier combiantions.</p>
<h2><a class="header" href="#native_gl" id="native_gl">native_gl</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/native_gl.rs">Source Code</a></p>
<p>Demonstrates how to access the underlying OpenGL system, if you should need it. Note that if you really want to write a GL application, this is a really inefficient way to do it---but it gets you started, and offers a way to perform quick OpenGL calls if you just need something fancy.</p>
<p><img src="./ex_bt_native_gl.jpg" alt="" /></p>
<h2><a class="header" href="#no_cls" id="no_cls">no_cls</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/no_cls.rs">Source Code</a></p>
<p>Mostly a debugging tool, this example shows that consoles accumulate data if you don't call <code>cls</code>. This was important for debugging the native console implementations and their dirty-render detection.</p>
<h2><a class="header" href="#post_process" id="post_process">post_process</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/postprocess.rs">Source Code</a></p>
<p>Demonstrates reading a REX Paint file (.xp), and rendering it to the screen. Enables or disables the terminal's post-processing options, screen-burn and uses scan-lines.</p>
<p><img src="./ex_bt_post.jpg" alt="" /></p>
<h2><a class="header" href="#return_error" id="return_error">return_error</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/return_error.rs">Source Code</a></p>
<p>Demonstrates how to return and act on errors from initialization, should you wish to do so.</p>
<h2><a class="header" href="#rex" id="rex">rex</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/rex.rs">Source Code</a></p>
<p>Loads Nyan Cat from an embedded REX Paint file, and renders it to the screen.</p>
<p><img src="./ex_bt_rex.jpg" alt="" /></p>
<h2><a class="header" href="#sparse" id="sparse">sparse</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/sparse.rs">Source Code</a></p>
<p>Demonstrates layering a sparse console on top of a simple console, with different fonts on each.</p>
<p><img src="./ex_bt_sparse.jpg" alt="" /></p>
<h2><a class="header" href="#sparse_cls" id="sparse_cls">sparse_cls</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/sparse_cls.rs">Source Code</a></p>
<p>Debugging tool, designed to help me notice when I break clearing sparse consoles again!</p>
<h2><a class="header" href="#sprites" id="sprites">sprites</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/sprites.rs">Source Code</a></p>
<p>Uses the sprite layer type (in its infancy) to animate some sprites as they run around the screen.</p>
<p><img src="./ex_bt_sprites.gif" alt="" /></p>
<h2><a class="header" href="#squishy" id="squishy">squishy</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/squishy.rs">Source Code</a></p>
<p>A benchmark tool that also demonstrates the ability to &quot;squish&quot; terminals by dynamically resizing the size of each tile.</p>
<h2><a class="header" href="#textblock" id="textblock">textblock</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/textblock.rs">Source Code</a></p>
<p>Demonstrates the text-block tool, and how it can help with large amounts of text.</p>
<p><img src="./ex_bt_textblock.jpg" alt="" /></p>
<h2><a class="header" href="#textsprites" id="textsprites">textsprites</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/textsprites.rs">Source Code</a></p>
<p>Demonstrates the &quot;multi-tile text sprite&quot; system. You can batch some characters together for quick rendering.</p>
<p><img src="./ex_bt_textsprites.gif" alt="" /></p>
<h2><a class="header" href="#tiles" id="tiles">tiles</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/tiles.rs">Source Code</a></p>
<p>Uses graphical fonts instead of ASCII/CP437 for a visual dungeon experience.</p>
<p><img src="./ex_bt_tiles.jpg" alt="" /></p>
<h2><a class="header" href="#unicode" id="unicode">unicode</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/unicode.rs">Source Code</a></p>
<p>Demonstrates that if you <em>really</em> want to (it's slow!), you can load a giant font containing lots of unicode and display multi-lingual terminals. Run this one in <code>release</code> mode. It takes far too long to start, otherwise.</p>
<p><img src="./ex_bt_unicode.jpg" alt="" /></p>
<h2><a class="header" href="#virtual_console" id="virtual_console">virtual_console</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/virtual_console.rs">Source Code</a></p>
<p>Demonstrates using a virtual console to hold a lot of data, and then displaying windows into the virtual console. This can be handy for logs, manuals and similar. <em>This should have a seizure warning</em></p>
<p><img src="./ex_bt_virtual_console.jpg" alt="" /></p>
<h2><a class="header" href="#walking" id="walking">walking</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/walking.rs">Source Code</a></p>
<p>Demonstrates walking around a map.</p>
<h2><a class="header" href="#walking_with_is_pressed" id="walking_with_is_pressed">walking_with_is_pressed</a></h2>
<p><a href="https://github.com/amethyst/bracket-lib/blob/master/bracket-terminal/examples/walking_with_is_pressed.rs">Source Code</a></p>
<p>The same walking demo, but using the <code>is_pressed</code> function (for advanced input) rather than the simple key enum.</p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                        
                            <a rel="prev" href="ex_rng.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        

                        
                            <a rel="next" href="consoles.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                
                    <a rel="prev" href="ex_rng.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>
                

                
                    <a rel="next" href="consoles.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
                
            </nav>

        </div>

        

        

        

        
        <script type="text/javascript">
            window.playground_copyable = true;
        </script>
        

        

        
        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
        

        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->
        

        

    </body>
</html>
